home *** CD-ROM | disk | FTP | other *** search
/ Ray Dream Studio 5 / Ray Dream.iso / pc / DreamSDK / Windows / INCLUDES / 3DBSTYPE.H next >
Encoding:
C/C++ Source or Header  |  1997-07-11  |  16.4 KB  |  528 lines

  1. /* $Id: 3DBSTYPE.H 1.43 1997/05/07 06:02:35 damien Exp $ */
  2. /*****************************************************************************\
  3. *                                                                             *
  4. * 3DBsType.h -     Basic 3D types definition                                               *
  5. *                                                                             *
  6. *   Common to EVX and COM interfacing.                                        *
  7. *   Uses QuickMath unless qUsesQuickMath is false.                            *
  8. *                                                                             *
  9. *           Copyright (c) 1995, Ray Dream, Inc. All rights reserved.          *
  10. *                                                                             *
  11. \*****************************************************************************/
  12.  
  13. #ifndef __3DBSTYPE__
  14. #define __3DBSTYPE__
  15.  
  16. // QuickMath. We use QMath.h by default
  17. // If you do not want to use QuickMath, define qUsesQuickMath and define the NUM3D;
  18. // VECTOR2D, and VECTOR3D types before including this file.
  19. #ifndef qUsesQuickMath
  20. #define qUsesQuickMath 1
  21. #endif
  22.  
  23. #if qUsesQuickMath
  24. #include "QMath.h"
  25. typedef QuickFix NUM3D;
  26. typedef QuickFixVector2 VECTOR2D;
  27. typedef QuickFixVector3 VECTOR3D;
  28. #else
  29. // type definitions for the toolkit SDK
  30. #ifdef _WIN
  31. #pragma warning(disable: 4244) // conversion from 'type1' to 'type2', possible loss of data
  32. #endif
  33.  
  34. typedef float NUM3D;
  35. struct VECTOR2D {
  36.     NUM3D& operator[](int i) {return fData[i];}
  37.     const NUM3D& operator[](int i) const {return fData[i];}
  38.     NUM3D fData[2];
  39.     };
  40. struct VECTOR3D {
  41.     NUM3D& operator[](int i) {return fData[i];}
  42.     const NUM3D& operator[](int i) const {return fData[i];}
  43.     NUM3D fData[3];
  44.     };
  45.  
  46. #define SQR(X) ((X)*(X))
  47.  
  48. #ifndef __MTYPES__
  49. #include "mtypes.h"
  50. #endif
  51.  
  52. #endif //qUsesQuickMath
  53.  
  54. #ifdef _MAC
  55. #ifdef qPowerPC
  56. typedef double Double;
  57. #else
  58. typedef long double Double;
  59. #endif
  60. #endif
  61.  
  62. #ifdef _WIN
  63. typedef double Double;
  64. #endif
  65.  
  66. struct I3DShInstance;
  67. struct IShRasterOffscreen;
  68.  
  69. /** Constants **************************************************/
  70.  
  71. //-- Shading Level
  72. enum ShadingLevel {
  73.     kShLvlNoChanges=-1,     // No Changes - Use renderer’s default shading level
  74.     kShLvlInvisible=0,         // Invisible - Do not render
  75.     kShLvlBBox=1,                 // Render bounding box only
  76.     kShLvlWireFrame=2,        // Wireframe
  77.     kShLvlPreview=3,            // Preview Shading - Fast and crude shading
  78.     kShLvlFullShading=4        // Full Shading
  79.     };
  80.  
  81. enum { 
  82.     kDefaultMapping = -1,
  83.   kParametricMapping=0,
  84.     kBoxMapping=1,
  85.     kCylindricalMapping=2,
  86.     kSphericalMapping=3,
  87.     kPassThruMapping=4
  88.     };
  89.  
  90. /** Base types defines **************************************************/
  91. typedef unsigned char BOOLEAN;
  92.  
  93. #ifndef NULL
  94. #define NULL 0
  95. #endif
  96.  
  97. #ifndef TRUE
  98. #define TRUE 1
  99. #endif
  100.  
  101. #ifndef FALSE
  102. #define FALSE 0
  103. #endif
  104.  
  105. /** 3D types defines **************************************************/
  106.  
  107. #ifndef BOX2D
  108. typedef struct BOX2D{
  109.     VECTOR2D        fMin;
  110.     VECTOR2D        fMax;
  111.     } BOX2D; 
  112. #define BOX2D BOX2D
  113. #endif
  114.  
  115. #ifndef BOX3D
  116. typedef struct BOX3D {
  117.     VECTOR3D        fMin;
  118.     VECTOR3D        fMax;
  119.     } BOX3D;
  120. #define BOX3D BOX3D
  121. #endif
  122.  
  123. // The i, j and k vectors
  124. // can be considered as the unit vectors of the Local System,
  125. // and the fix, fiy,... values as they coordinates in the
  126. // Global Coordinates System.
  127. typedef struct MATRIX3D {
  128.     NUM3D fix, fjx, fkx,
  129.                 fiy, fjy, fky,
  130.                 fiz, fjz, fkz;
  131.     } MATRIX3D;
  132.  
  133.  
  134. // Matrix 3 x 3 + translation
  135. typedef struct TRANSFORM3D {
  136.     MATRIX3D        fR;        // Rotation 3 x 3 matrix
  137.     VECTOR3D        fT;        // Translation
  138.     } TRANSFORM3D;
  139.  
  140. // Tree transformation
  141. typedef struct TREETRANSFORM3D {
  142.     MATRIX3D        fR;        // Rotation 3 x 3 matrix
  143.     VECTOR3D        fT;        // Translation
  144.     NUM3D                fS;        // Uniform scaling
  145.     } TREETRANSFORM3D;
  146.  
  147. #ifndef AFFINETRANSFORM
  148. struct AffineTransform {
  149.     NUM3D fR[3][3];
  150.     NUM3D fT[3];
  151.     };
  152. #define AFFINETRANSFORM AffineTransform
  153. #endif
  154.  
  155. #ifndef COLOR3D
  156. typedef struct COLOR3D {
  157.     long    Mode;        // Color model. 0=RGB, 1=CMYK
  158.     NUM3D    R;            // Red or Cyan
  159.     NUM3D    G;            // Green or Magenta
  160.     NUM3D    B;            // Blue or Yellow
  161.     NUM3D    A;            // N/A or Black
  162. } COLOR3D;
  163. #define COLOR3D COLOR3D
  164. #endif
  165.  
  166. typedef struct RGBCOLOR3D {
  167.     unsigned short R;
  168.     unsigned short G;
  169.     unsigned short B;
  170.     } RGBCOLOR3D;
  171.  
  172. #ifndef RECT3D
  173. typedef struct RECT3D {
  174.     short        top;
  175.     short        left;
  176.     short        bottom;
  177.     short        right;
  178. } RECT3D;
  179. #define RECT3D RECT3D
  180. #endif
  181.  
  182. #ifndef LRECT3D
  183. typedef struct LRECT3D {
  184.     long        top;
  185.     long        left;
  186.     long        bottom;
  187.     long        right;
  188. } LRECT3D;
  189. #define LRECT3D LRECT3D
  190. #endif
  191.  
  192. #ifndef POINT3D
  193. typedef struct POINT3D {
  194.     short        h;
  195.     short        v;
  196.     } POINT3D;
  197. #define POINT3D POINT3D
  198. #endif
  199.  
  200. #ifndef LPOINT3D
  201. typedef struct LPOINT3D {
  202.     long        v;            // Note the inverse order of v and h
  203.     long        h;
  204.     } LPOINT3D;
  205. #define LPOINT3D LPOINT3D
  206. #endif
  207.  
  208. typedef struct {
  209.     long        fId;
  210.     long        fPriority;
  211.     long        fMessage;
  212.     long        fWhen;
  213.     short        fLocalWhereH;
  214.     short        fLocalWhereV;
  215.     short        fGlobalWhereH;
  216.     short        fGlobalWhereV;
  217.     short        fPressure;
  218.     BOOLEAN    fLeftButton;
  219.     BOOLEAN    fRightButton;
  220.     BOOLEAN    fCommandKey;
  221.     BOOLEAN    fShiftKey;
  222.     BOOLEAN    fAlphaLock;
  223.     BOOLEAN    fOptionKey;
  224.     BOOLEAN    fControlKey;
  225.     BOOLEAN    fAutoKey;
  226.     short        fChar;
  227.     short        fKey;
  228.     short        fClickCount;
  229.     long        fActionNumber;
  230.     void*        fReserved;
  231.     } PLATFORMEVENT;
  232.  
  233. typedef struct VERTEX3D {
  234.     VECTOR3D        fVertex;        // x, y, z vertex coordinates
  235.     VECTOR3D        fNormal;        // Nx, Ny, Nz normal values at that vertex
  236.     VECTOR2D        fUV;            // Texture u,v values at that vertex
  237. } VERTEX3D;
  238.  
  239. typedef struct FACET3D{
  240.     VERTEX3D    fVertices[3];        // The facet three vertices
  241.     short            fUVSpace;                // UV Space ID this facet belongs to
  242.     short            fReserved;            // Reserved - 0
  243.     } FACET3D;
  244.  
  245. typedef struct PATCH3D{
  246.     VECTOR3D    fVertices[4][4];        // The patch 16 vertices
  247.     NUM3D            fu[2];                            // u values at the patch boundaries
  248.     NUM3D            fv[2];                            // v values at the patch boundaries
  249.     short            fUVSpace;                        // UV Space ID this patch belongs to
  250.     short            fReserved;                    // Reserved - 0
  251.     } PATCH3D;
  252.  
  253. struct FacetMesh {
  254.     long fNbrFacets;
  255.     long fNbrVertices;
  256.     long fFacetStreamSize;
  257.     void *fFacetStream;
  258.     VERTEX3D *fVertices;
  259.     };
  260.  
  261. /** Shading defines **************************************************/
  262.  
  263.  
  264. enum {
  265.     kColorChannel=1,
  266.     kSpecularityChannel=2,
  267.     kShininessChannel=4,
  268.     kNormalChannel=8,
  269.     kReflectionChannel=16,
  270.     kTransparencyChannel=32,
  271.     kRefractionChannel=64,
  272.     kGlowChannel=128,
  273.     kAllChannels = 1+2+4+8+16+32+64+128
  274.     };
  275.  
  276. typedef struct ShadingFlags{
  277.     BOOLEAN    fCallOnce;                    // Constant Shader: The shader needs to be called only once for the whole object or shading area
  278.     BOOLEAN    fNeedsColor;                // Needs Color - Not used
  279.     BOOLEAN    fNeedsPoint;                // Needs surface point in Global Coordinates
  280.     BOOLEAN    fNeedsNormal;                // Needs surface Normal in Global Coordinates
  281.     BOOLEAN    fNeedsIsoU;                    // Needs U iso-parametric vector in Local Coordinates
  282.     BOOLEAN    fNeedsIsoV;                    // Needs V iso-parametric vector in Local Coordinates
  283.     BOOLEAN    fNeedsUV;                        // Needs u,v texture values
  284.     BOOLEAN    fNeedsPointLoc;            // Needs surface point in Local Coordinates
  285.     BOOLEAN    fNeedsNormalLoc;        // Needs surface Normal in Local Coordinates
  286.     BOOLEAN    fNeedsPixelRatio;        // Needs Pixel Ratio - Not used yet - Future use
  287.     BOOLEAN    fChangesNormal;            // The shader changes the Normal. The new Normal will have to be read in ShadingOut::fChangedNormal
  288.     long fConstantChannelsMask;
  289. } ShadingFlags;
  290.  
  291. typedef struct ShadingIn    { 
  292.     COLOR3D        fColor;                // Color - Not used - For future use
  293.     VECTOR3D    fPoint;                // Surface point in Global Coordinates
  294.     VECTOR3D    fNormal;            // Surface Normal in Global Coordinates
  295.     VECTOR3D    fIsoU;                 // U iso-parametric vector in Local Coordinates
  296.     VECTOR3D    fIsoV;                // V iso-parametric vector in Local Coordinates
  297.     VECTOR2D    fUV;                    // u,v texture values
  298.     unsigned long    fUVSpaceID;        // UV Space ID
  299.     VECTOR3D    fPointLoc;        // Surface point in Local Coordinates
  300.     VECTOR3D    fNormalLoc;        // Surface Normal in Local Coordinates
  301.     NUM3D            fPixelRatio;    // Pixel Ratio - Not used - For future use
  302. } ShadingIn;
  303.  
  304. typedef struct ShadingOut{ 
  305.     COLOR3D        fColor;                        // Diffuse Color (Kd)
  306.     COLOR3D        fSpecularColor;        // Specular Color (Ks)
  307.     NUM3D            fSpecularSize;        // Specular highlight size (Ns)
  308.     NUM3D            fAmbient;                    // Ambient factor (Fa)
  309.     NUM3D            fLambert;                    // Diffuse factor (Fd)
  310.     COLOR3D        fReflection;            // Reflectivity (Rx)
  311.     COLOR3D        fTransparency;        // Transparency (Tx)
  312.     NUM3D            fRefractiveIndex;    // Refraction index (Nr)
  313.     COLOR3D        fGlow;                        // Glow color
  314.     VECTOR3D    fChangedNormal;     // Changed Normal in Global Coordinates
  315. } ShadingOut;
  316.  
  317. typedef struct UVSpaceInfo    {
  318.     unsigned long        fID;        // UV Space ID
  319.     VECTOR2D                fMin;        // UV Space minimum boundaries
  320.     VECTOR2D                fMax;        // UV Space maximum boundaries
  321.     BOOLEAN                 fWraparound[2];        // Tells is the UV Space is closed in the U or V direction
  322.     } UVSpaceInfo;
  323.  
  324. typedef struct ShadingInOut{
  325.     ShadingIn*         fIn;            // Shading input parameters
  326.     ShadingOut*     fOut;            // Shading output parameters
  327.     UVSpaceInfo*    fUVInfo;    // UV Space information
  328.     unsigned long    fCurrentCompletionMask;    // Internal flags for shaders. Must be set to 0x7F before calling DoShade
  329. } ShadingInOut;
  330.  
  331.  
  332. typedef struct FixPtRect {    // Rectangle in a Shading Element.
  333.     NUM3D fTop;
  334.     NUM3D fLeft;
  335.     NUM3D fBottom;
  336.     NUM3D fRight; 
  337.     } FixPtRect;
  338.     
  339. typedef struct FixPtRect ShadingElemRect;
  340.  
  341. // Shading Element:
  342. // A Shading Element defines an area of Shading on an Object surface.
  343. // The area is defined in the surface UV Space.
  344. // fBBox and fShaderBox define the same rectangle in two different systems. fBBox is
  345. // in the UV Space, and thus defines the extent of the Shading Element on the Object
  346. // surface. fShaderBox defines the boundaries of the UV values that will be passed to
  347. // the Shader. Therefore, moving or rezising the Shading Element on the object surface
  348. // will not change the shading inside the Shading Element (provided that the Shader bases
  349. // its calculations on the UV values. Otherwise the discussion is pointless).
  350. typedef struct ShadingElem {
  351.     ShadingElemRect            fBBox;                // Extent of the Shading Element in the UV Space
  352.     ShadingElemRect            fShaderBox;        // Extent of the Shading Element as seen by the shader
  353.     NUM3D                                 fOpacity;            // Opacity of the Shading Element vs. whatever other Shader Elements may be under
  354.  } ShadingElem;
  355.  
  356. /*****************************************************************************\
  357. *  Lighting Model:                                                            *
  358. *                                                                             *
  359. *                    --                 --                                    *
  360. *                    \                  \             Ns                      *
  361. *    Color = Fa*Kd*Ia + / Fd*Kd*Ii(Li.N) + / Ks*Ii*(Ri.N)    +  Rx*(reflected color) + Tx*(transmitted color)
  362. *                        --i                --i                                   *
  363. *                                                                             *
  364. *   With:                                                                     *
  365. *      Ia: Ambient light color                                                *
  366. *      Ii: Color of the light source #i                                       *
  367. *      Li: Unit vector pointing from the surface point to light source #i     *
  368. *      N : Surface Normal                                                     *
  369. *      Ri: Unit vector giving the reflection direction of the light source #i *
  370. *                                                                             *
  371. *  V1.V2 is a scalar product between 2 vectors:                               *
  372. *      V1.V2 = V1.x*V2.x + V1.y*V2.y + V1.z*V2.z                              *
  373. *                                                                             *
  374. *  Refracted ray direction is computed using Snell's law:                     *
  375. *       Nr1 * Sinus(alpha1) = Nr2 * Sinus(alpha2)                             *
  376. *                                                                             *
  377. *                                                                             *
  378. \*****************************************************************************/
  379.  
  380.  
  381. /** Ray-tracing defines **************************************************/
  382.  
  383. typedef struct Ray3D {
  384.     VECTOR3D    fOrigin;                // Origin of the ray
  385.     VECTOR3D    fDirection;            // Direction of the ray
  386.     NUM3D            fFocalPoint;        // ???
  387.     NUM3D            fAngle;                    // ???
  388.     NUM3D            fWidthAtFocal;    // ???
  389. } Ray3D;
  390.  
  391. class RDList;
  392.  
  393. typedef struct RayHit3D{
  394.     VECTOR3D        fPosition;                // Intersection point in Local Coordinates
  395.     VECTOR3D        fNormal;                    // Normal at that point in Local Coordinates
  396.     VECTOR2D        fUV;                            // (u,v) texture values at that point
  397.     NUM3D                ft;                                // t parameter along the ray: fPosition = RayOrigin + t * RayDirection
  398.     VECTOR3D        fIsoU;                        // Isoparametric U vector in the Object Local Coordinates
  399.     VECTOR3D        fIsoV;                        // Isoparametric V vector in the Object Local Coordinates
  400.     I3DShInstance        *fInstance;        // instance that was hit
  401.     BOOLEAN            fShouldSetUV;            // TRUE if fUV should be set
  402.     BOOLEAN            fShouldSetIsoUV;    // TRUE if fIsoU and fIsoV should be set
  403.     FACET3D            fFacet; //facet hit
  404.     NUM3D        fBaryCoord[3]; //barycentric coordinates of hit point on hot facet
  405.     void (*fCalcInfo)(RayHit3D &me);
  406.     AFFINETRANSFORM fT;
  407.     AFFINETRANSFORM fInvT;
  408. } RayHit3D;
  409.  
  410. typedef BOOLEAN (*FilterHitProc) (I3DShInstance* instance);
  411.  
  412. typedef struct RayHitParameters {
  413.     NUM3D     tmin;
  414.     NUM3D     tmax;
  415.     BOOLEAN    fShouldSetS;
  416.     BOOLEAN    fShouldSetUV;
  417.     BOOLEAN    fZBShading;
  418.     BOOLEAN    fNoGrid;
  419.     void *fFilterInstance;
  420.     BOOLEAN fRenderInfinitePrimitives;
  421. } RayHitParameters;
  422.  
  423. typedef void (*RayHitCallback)(Ray3D* aR, NUM3D tmin, NUM3D tmax, RayHit3D* hit, void* privData);
  424. //typedef void (*RayTraceCallback)(HitInfo* hitInfo, void* privData);
  425.  
  426.  
  427. //*********************************************************************************
  428.  
  429. class SDGraphicDevice;
  430. struct I3DShInstance;
  431. typedef void (*EnumPatchesCallback) (PATCH3D* patch, void* privData);
  432. typedef void (*EnumFacetsCallback) (FACET3D* facet, void* privData);
  433.  
  434. typedef struct GBufferData {
  435.     void* data;
  436.     long channelBits;
  437.     long channelOffsetBits;
  438.     long columnBits;
  439.     long rowBits;
  440.     short nbrChannels;
  441.     } GBufferData;
  442.  
  443. typedef struct GBuffer {
  444.     GBufferData color;
  445.     GBufferData distance;
  446.     GBufferData position;
  447.     GBufferData normal;
  448.     GBufferData alpha;
  449.     GBufferData index;
  450.     GBufferData surface;
  451.     } GBuffer;
  452.  
  453. typedef struct LightTraceElement {
  454.     VECTOR3D fPoint1;
  455.     VECTOR3D fVector1;
  456.     VECTOR3D fPoint2;
  457.     VECTOR3D fVector2;
  458. } LightTraceElement;
  459.  
  460.  
  461. //****** Parameter blocks for building extrusions ******************************
  462.  
  463. #ifdef __cplusplus
  464. struct I3DShCrossSection;
  465. #else
  466. typedef void* I3DShCrossSection;
  467. #endif
  468.  
  469.  
  470. typedef struct Path3DPoint {
  471.     VECTOR3D            fVertex;                // Vertex
  472.     // Fill these only if using envelopes:
  473.     VECTOR3D            fTopEnv;                // Envelope: top curve on right wall
  474.     VECTOR3D            fBotEnv;                // Envelope: bottom curve on right wall
  475.     VECTOR3D            fLeftEnv;                // Envelope: left curve on floor
  476.     VECTOR3D            fRightEnv;            // Envelope: right curve on floor
  477.     } Path3DPoint;
  478.  
  479. typedef struct ExtrusionHeaderPB {
  480.     Path3DPoint                f3DPathPrevControl1;        // Don't fill this if 1st section
  481.     Path3DPoint                f3DPathPrevControl2;        // Don't fill this if 1st section
  482.     VECTOR3D                    f3DPathVertex;                    // Put 0 in x and z unless you know what you're doing
  483.     BOOLEAN                        fFill;
  484.     BOOLEAN                        fSkinToNext;
  485.     } ExtrusionHeaderPB;
  486.  
  487. typedef struct ExtrusionPB {        // Adding a non-automatic cross-section
  488.     ExtrusionHeaderPB        fHeader;
  489.     //-- Specific parameters:
  490.     I3DShCrossSection*    fCrossSection;
  491.     NUM3D                                fTwisting;            // Twisting angle
  492.     } ExtrusionPB;
  493.  
  494. typedef struct ExtrusionAutoPB {        // Adding an automatic cross-section
  495.     ExtrusionHeaderPB        fHeader;
  496.     //-- Specific parameters:
  497.     NUM3D                                fTopScaling;
  498.     NUM3D                                fBotScaling;
  499.     NUM3D                                fLeftScaling;
  500.     NUM3D                                fRightScaling;
  501.     } ExtrusionAutoPB;
  502.  
  503. // Envelope flags:
  504. enum { kExtrFree=0,             // Free Envelope
  505.                 kExtrSym=1,             // Symetrical Envelope
  506.                 kExtrSemiSym=6};    // Semi-symetrical Envelope
  507.  
  508. //*********************************************************************************
  509.  
  510. #ifdef __cplusplus
  511. struct I3DShTreeElement;
  512. #else
  513. typedef void* I3DShTreeElement;
  514. #endif
  515.  
  516. typedef struct CollisionInfo {
  517.     I3DShTreeElement *fObject1;
  518.     I3DShTreeElement *fObject2;
  519.     VECTOR3D fHitPosition;
  520.     VECTOR3D fNormal1;
  521.     VECTOR3D fNormal2;
  522.     VECTOR3D fVelocity1;
  523.     VECTOR3D fVelocity2;
  524.     } CollisionInfo;
  525.          
  526. #endif
  527.  
  528.